home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / termtest.zip / TERM.BAS next >
BASIC Source File  |  1991-10-07  |  2KB  |  78 lines

  1. DEFINT A-Z
  2.  
  3. DECLARE SUB Filter (InString$)
  4. modem$ = COMMAND$
  5.  
  6. COLOR 7, 1                      ' Set screen color.
  7. CLS
  8.  
  9. Quit$ = CHR$(0) + CHR$(16)      ' Value returned by INKEY$
  10.                                 ' when ALT+q is pressed.
  11.  
  12. ' Set up prompt on bottom line of screen and turn cursor on:
  13. LOCATE 24, 1, 1
  14. PRINT STRING$(80, "_");
  15. LOCATE 25, 1
  16. PRINT TAB(30); "Press ALT+q to quit";
  17.  
  18. VIEW PRINT 1 TO 23              ' Print between lines 1 & 23.
  19.  
  20. ' Open communications (1200 baud, no parity, 8-bit data,
  21. ' 1 stop bit, 256-byte input buffer):
  22.         PRINT "Opening Com port 2 at 1200 baud"
  23.         OPEN "COM2:1200,N,8,1" FOR RANDOM AS #1 LEN = 256
  24.  
  25. DO                              ' Main communications loop.
  26.  
  27.    KeyInput$ = INKEY$           ' Check the keyboard.
  28.  
  29.    IF KeyInput$ = Quit$ THEN    ' Exit the loop if the user
  30.       EXIT DO                   ' pressed ALT+q.
  31.  
  32.    ELSEIF KeyInput$ <> "" THEN  ' Otherwise, if the user has
  33.       PRINT #1, KeyInput$;      ' pressed a key, send the
  34.    END IF                       ' character typed to the modem.
  35.  
  36.    ' Check the modem. If characters are waiting (EOF(1) is
  37.    ' true), get them and print them to the screen:
  38.    IF NOT EOF(1) THEN
  39.  
  40.       ' LOC(1) gives the number of characters waiting:
  41.       ModemInput$ = INPUT$(LOC(1), #1)
  42.  
  43.       Filter ModemInput$        ' Filter out line feeds and
  44.       PRINT ModemInput$;        ' backspaces, then print.
  45.    END IF
  46. LOOP
  47.  
  48. CLOSE                           ' End communications.
  49. CLS
  50. END
  51.  
  52. '
  53. ' ========================= FILTER ==========================
  54. '     Filters characters in an input string.
  55. ' ============================================================
  56. '
  57. SUB Filter (InString$) STATIC
  58.  
  59.    ' Look for backspace characters and recode them to
  60.    ' CHR$(29) (the LEFT cursor key):
  61.    DO
  62.       BackSpace = INSTR(InString$, CHR$(8))
  63.       IF BackSpace THEN
  64.          MID$(InString$, BackSpace) = CHR$(29)
  65.       END IF
  66.    LOOP WHILE BackSpace
  67.  
  68.    ' Look for line-feed characters and remove any found:
  69.    DO
  70.       LineFeed = INSTR(InString$, CHR$(10))
  71.       IF LineFeed THEN
  72.          InString$ = LEFT$(InString$, LineFeed - 1) + MID$(InString$, LineFeed + 1)
  73.       END IF
  74.    LOOP WHILE LineFeed
  75.  
  76. END SUB
  77.  
  78.